package com.blacktea.creationalpatterns.factorymethod.service;

import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONUtil;
import com.blacktea.creationalpatterns.simplefactorymodel.service.Cat;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Import;

import java.util.Map;
import java.util.Optional;

/**
 * @description:
 * @author: black tea
 * @date: 2023/3/19 1:10
 */
@Slf4j
@Import(SpringUtil.class) // 如果需要在这里调用Spring管理的Bean，需要导入 ApplicationContext
public class UserServiceImpl implements UserService {

    @Override
    public void  addUser(Map<String, Object> params) {
        log.info("添加用户,参数是:{}", JSONUtil.toJsonStr(params));

       Optional.ofNullable((Cat) SpringUtil.getBean("cat"))
               .ifPresent(Cat::makeSound);

    }
}
